`
https://leetcode.cn/problems/longest-substring-without-repeating-characters/
`

/**
 * @param {string} s
 * @return {number}
 */
var lengthOfLongestSubstring = function (s) {
  if (s.length <= 1) return s.length
  const window = {}
  let res = 0
  let left = 0, right = 0
  while (right < s.length) {
    const c = s[right]
    right++
    window[c] = (window[c] || 0) + 1
    while (window[c] > 1) {
      const d = s[left]
      left++
      window[d] = (window[d] || 0) - 1
    }
    res = Math.max(res, right - left)
  }
  return res
};